<template>
    <el-dialog :model-value="isShow" title="备注订单" width="30%" @close="emit('hide')">
        <el-form ref="formRef" :rules="rules">
            <el-form-item label="操作备注：" prop="inputVal">
            <textarea name="" id="" cols="30" rows="10" v-model="inputVal" @input="change"></textarea>
      </el-form-item>
        </el-form>
        <!-- <div class="el-form-item">
            <span>操作备注：</span>
            <textarea name="" id="" cols="30" rows="10" v-model="inputVal" @input="change"></textarea>
        </div> -->
        <template #footer>
            <span class="dialog-footer">
                <el-button @click="emit('hide')">取消</el-button>
                <el-button type="primary" @click="submitFn">
                    确定
                </el-button>
            </span>
        </template>
    </el-dialog>
</template>

<script setup lang='ts'>
import { ElMessage, ElMessageBox, FormInstance } from 'element-plus';
import { ref } from 'vue';
import { getUpdateCloseApi, getUpdateNoteApi } from './api';
import { useRoute, useRouter } from "vue-router"
const props = defineProps({
    isShow: {
        type: Boolean,
        default: true
    },
    status: {
        type: Number,
        default: 0
    },
    deleteList: {
        type: Object,
        default: []
    }
})

const route = useRoute()
const inputVal = ref('')
const rules = {
    inputVal: [{ required: true, trigger: "blur", message: "请填写备注内容" }],
};
const emit = defineEmits(['hide'])
const formRef = ref<FormInstance>();
const change = () => {
    console.log(inputVal.value);

}
const submitFn = () => {

    if (props.status === 0) {
        getUpdateCloseApi(props.deleteList as any, inputVal.value as string).then(res => {
            if (res.code === 200) {
                ElMessage.success('修改成功')
                emit('hide')
            }
        })
    } else {
        ElMessageBox.confirm("是否要备注订单?", "提示?", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: 'warning',
        }).then(() => {
            getUpdateNoteApi(parseInt(route.query.id as string), inputVal.value as string, props.status).then(res => {
                if (res.code === 200) {
                    ElMessage.success('订单备注成功')
                    emit('hide', true)
                    formRef.value?.resetFields()
                }
            })
        })
    }
}
</script>

<style>

</style>
